package ligafutbol;

import clases.*;
import java.util.*;
import java.util.ArrayList;

public class frmClasificacion extends javax.swing.JFrame {

    /** Creates new form frmClasificacion */
    ArrayList<Equipo> lista;
    

    public frmClasificacion() {
        initComponents();
        
        lista = Equipo.obtenerEquipo();

        miTabla mt = new miTabla();
        mt.iniciarDatos(lista);

        this.tblClasificacion.setModel(mt);
        this.tblClasificacion.setRowHeight(22);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbTitulo = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblClasificacion = new javax.swing.JTable();
        lbBanner = new javax.swing.JLabel();
        btnVolver = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lbTitulo.setFont(new java.awt.Font("Tahoma", 1, 14));
        lbTitulo.setText("CLASIFICACIÓN LIGA BBVA");

        tblClasificacion.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(tblClasificacion);

        btnVolver.setText("Volver");
        btnVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVolverActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(269, 269, 269)
                .addComponent(btnVolver)
                .addContainerGap(315, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 627, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lbBanner)
                        .addContainerGap(296, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbBanner)
                    .addComponent(lbTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                .addComponent(btnVolver)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVolverActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_btnVolverActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void inicio() {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmClasificacion().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnVolver;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbBanner;
    private javax.swing.JLabel lbTitulo;
    private javax.swing.JTable tblClasificacion;
    // End of variables declaration//GEN-END:variables

    class miTabla extends javax.swing.table.AbstractTableModel{
        Object datos[][] = null;
        String columns[] = null;
        Class tipos[] = null;
        Boolean editables[] = null;

        miTabla(){
            datos = new Object[][]{};
            columns = new String[]{"Número", "Equipo", "PJ", "PG", "PP", "PE", "GF", "GC", "Puntos", "Dif Puntos"};
            tipos = new Class[]{java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class,
                        java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class,
                        java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class};
            editables = new Boolean[]{false,false, false, false, false, false, false, false, false, false};
        }

        public int getRowCount() {
            return lista.size();
        }

        public int getColumnCount() {
            return columns.length;
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            return datos[rowIndex][columnIndex];
        }

        private void iniciarDatos(ArrayList l){
            Object d [][] = new Object[l.size()][columns.length];

            int i = 0;
            Iterator it = l.iterator();
            while(it.hasNext()){
                Equipo e = (Equipo)it.next();
                d[i][0] = i+1;
                d[i][1] = e.getNombre();
                d[i][2] = Jornada.numeroJornadas();
                d[i][3] = e.getPartidosGanado();
                d[i][4] = e.getPartidosEmpatado();
                d[i][5] = e.getPartidosPerdido();
                d[i][6] = e.getNumGoles();
                d[i][7] = e.getPuntos();
                d[i][8] = e.getDiferenciaGoles();
                
                i++;
            }
            datos = d;
        }

    }
}
